package com.yezi.lampcourt.ui.presenter;

import android.content.Context;

import com.yezi.lampcourt.base.BaseEntity;
import com.yezi.lampcourt.base.BaseObserver;
import com.yezi.lampcourt.base.BasePresenter;
import com.yezi.lampcourt.entity.CourtBean;
import com.yezi.lampcourt.http.HttpFactory;
import com.yezi.lampcourt.http.LampCourtService;
import com.yezi.lampcourt.http.RxSchedulers;
import com.yezi.lampcourt.ui.contract.CourtListContract;

import java.util.List;

/**
 * Created by HongMing Ye
 * on 2017/10/9 0009.
 */

public class CourtListPresenter extends BasePresenter<CourtListContract.CourtListView> implements CourtListContract.CourtListPresenterInterface {

    public CourtListPresenter(Context context, CourtListContract.CourtListView view) {
        super(context, view);
    }

    @Override
    public void getCourtList() {
        HttpFactory.createNormalService(LampCourtService.class)
                .getCourtList()
                .compose(RxSchedulers.<BaseEntity<List<CourtBean>>>io_main())
                .subscribeWith(new BaseObserver<List<CourtBean>>(mContext) {
                    @Override
                    protected void onHandleSuccess(List<CourtBean> courtBeen) {
                        mView.getCourtListSuccess(courtBeen);
                    }

                    @Override
                    protected void onHandleError(String msg) {
                        mView.getCourtListFail(msg);
                    }
                });
    }
}
